package com.sundi.ecupms.web;


import com.alibaba.fastjson.JSON;
import com.sundi.eccommon.vo.ResultEntity;
import com.sundi.ecupms.entity.EcMenu;
import com.sundi.ecupms.service.IEcMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-02-24
 */
@RestController
@RequestMapping("/upms/menu")
@Slf4j
public class EcMenuController {

    @Autowired
    IEcMenuService menuService;

    @RequestMapping("/getMenuByUserName")
    public ResultEntity getMenuByUserName(Principal member){
        log.info("当前登录用户的信息为:{}", JSON.toJSONString(member));
//        UsernamePasswordAuthenticationToken u = (UsernamePasswordAuthenticationToken) member;
//        //log.info(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        //TODO:admin 死数据
        List<EcMenu> menus = menuService.getMenuByUserName(member.getName());
        return ResultEntity.ok(menus);
    }

}
